package com.jing.weibo.controller.user;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jing.system.comm.BaseController;
import com.jing.weibo.pojo.user.UserInfo;
import com.jing.weibo.pojo.user.UserPointLog;
import com.jing.weibo.service.user.UserPointLogService;

/**
 * 用户积分记录的Controller
 * @author jing.yue
 * @version 2012/09/29 1.0.0
 */
@Controller
public class PointController extends BaseController {

	private static final Logger logger = Logger.getLogger(PointController.class);
	
	@Autowired
	private UserPointLogService userPointLogService;

	/**
	 * 根据用户名获取用户积分记录信息
	 * @return
	 */
	@RequestMapping(value = "/point/json/findByUsernamePoint")
	@ResponseBody
	public ModelMap findByUsernamePoint(HttpServletRequest request, UserPointLog userPointLog) {
		String result = null;
		Map<String, Object> map = null;
		UserInfo userInfo = getSessionUser(request);
		try {
			userPointLog.setUsername(userInfo.getUsername());
			map = userPointLogService.findByUsernamePoint(userPointLog);
			result = SUCCESS;
		} catch (Exception e) {
			logger.error(userInfo.getNickname() + ": 根据用户名获取用户妞币记录信息异常!", e);
			result = ERROR;
		}
		ModelMap modelMap = new ModelMap();
		modelMap.put("data", map);
		modelMap.put("result", result);
		return modelMap;
	}
}